home *** CD-ROM | disk | FTP | other *** search
/ United Public Domain Gold 2 / United Public Domain Gold 2.iso / utilities / pu248.dms / pu248.adf / Intuition / IDCMP / Example6.c < prev    next >
C/C++ Source or Header  |  1992-05-01  |  6KB  |  178 lines

  1. /***********************************************************/
  2. /*                                                         */
  3. /* Amiga C Encyclopedia (ACE) V3.0      Amiga C Club (ACC) */
  4. /* -------------------------------      ------------------ */
  5. /*                                                         */
  6. /* Book:    ACM Intuition               Amiga C Club       */
  7. /* Chapter: IDCMP                       Tulevagen 22       */
  8. /* File:    Example6.c                  181 41  LIDINGO    */
  9. /* Author:  Anders Bjerin               SWEDEN             */
  10. /* Date:    92-05-01                                       */
  11. /* Version: 1.10                                           */
  12. /*                                                         */
  13. /*   Copyright 1992, Anders Bjerin - Amiga C Club (ACC)    */
  14. /*                                                         */
  15. /* Registered members may use this program freely in their */
  16. /*     own commercial/noncommercial programs/articles.     */
  17. /*                                                         */
  18. /***********************************************************/
  19.  
  20. /* This program explains how to use the IDCMP flag VANILLAKEY. */
  21.  
  22.  
  23.  
  24. #include <intuition/intuition.h>
  25.  
  26.  
  27.  
  28. struct IntuitionBase *IntuitionBase;
  29.  
  30.  
  31.  
  32. /* Declare a pointer to a Window structure: */ 
  33. struct Window *my_window;
  34.  
  35. /* Declare and initialize your NewWindow structure: */
  36. struct NewWindow my_new_window=
  37. {
  38.   50,             /* LeftEdge    x position of the window. */
  39.   25,             /* TopEdge     y positio of the window. */
  40.   320,            /* Width       320 pixels wide. */
  41.   100,            /* Height      100 lines high. */
  42.   0,              /* DetailPen   Text should be drawn with colour reg. 0 */
  43.   1,              /* BlockPen    Blocks should be drawn with colour r. 1 */
  44.   CLOSEWINDOW|    /* IDCMPFlags  We will recieve a message when the user */
  45.                   /*             selects the Close window gad.           */
  46.  
  47.   VANILLAKEY,     /*             We will also recieve a message whenever */
  48.                   /*             the user presses/releases a key.        */
  49.  
  50.   SMART_REFRESH|  /* Flags       Intuition should refresh the window. */
  51.   WINDOWCLOSE|    /*             Close Gadget. */
  52.   WINDOWDRAG|     /*             Drag gadget. */
  53.   WINDOWDEPTH|    /*             Depth arrange Gadgets. */
  54.   WINDOWSIZING|   /*             Sizing Gadget. */
  55.   ACTIVATE,       /*             The window should be Active when opened. */
  56.   NULL,           /* FirstGadget No gadgets connected to this window. */
  57.   NULL,           /* CheckMark   Use Intuition's default CheckMark. */
  58.   "PRESS MY KEYS",/* Title       Title of the window. */
  59.   NULL,           /* Screen      Connected to the Workbench Screen. */
  60.   NULL,           /* BitMap      No Custom BitMap. */
  61.   100,            /* MinWidth    We will not allow the window to become */
  62.   50,             /* MinHeight   smaller than 100 x 50, and not bigger */
  63.   400,            /* MaxWidth    than 400 x 200. */
  64.   200,            /* MaxHeight */
  65.   WBENCHSCREEN    /* Type        Connected to the Workbench Screen. */
  66. };
  67.  
  68.  
  69.  
  70. /**************************************************************************/
  71. /* Extra information:                                                     */
  72. /* Whenever the user presses/releases a key will we recieve a message.    */
  73. /* The Code part of the message contains the translated keykode (Default  */
  74. /* keymap used). (See Appendix * for more information about ASCII codes.) */
  75. /**************************************************************************/
  76.  
  77.  
  78.  
  79. main()
  80. {
  81.   /* Boolean variable used for the while loop: */
  82.   BOOL close_me;
  83.  
  84.   ULONG class;      /* IDCMP flag. */
  85.   USHORT code;      /* Code. */
  86.  
  87.   /* Pointer to an IntuiMessage structure: */
  88.   struct IntuiMessage *my_message;
  89.  
  90.  
  91.  
  92.   /* Before we can use Intuition we need to open the Intuition Library: */
  93.   IntuitionBase = (struct IntuitionBase *)
  94.     OpenLibrary( "intuition.library", 0 );
  95.   
  96.   if( IntuitionBase == NULL )
  97.     exit(); /* Could NOT open the Intuition Library! */
  98.  
  99.  
  100.  
  101.   /* We will now try to open the window: */
  102.   my_window = (struct Window *) OpenWindow( &my_new_window );
  103.   
  104.   /* Have we opened the window succesfully? */
  105.   if(my_window == NULL)
  106.   {
  107.     /* Could NOT open the Window! */
  108.     
  109.     /* Close the Intuition Library since we have opened it: */
  110.     CloseLibrary( IntuitionBase );
  111.  
  112.     exit();  
  113.   }
  114.  
  115.  
  116.  
  117.   /* We have opened the window, and everything seems to be OK. */
  118.  
  119.   printf("Press some keys!\n\n");
  120.  
  121.  
  122.  
  123.   close_me = FALSE;
  124.  
  125.   /* Stay in the while loop until the user has selected the Close window */
  126.   /* gadget: */
  127.   while( close_me == FALSE )
  128.   {
  129.     /* Wait until we have recieved a message: */
  130.     Wait( 1 << my_window->UserPort->mp_SigBit );
  131.  
  132.  
  133.     /* As long as we can collect messages successfully we stay in the */
  134.     /* while-loop: */
  135.     while(my_message = (struct IntuiMessage *) GetMsg(my_window->UserPort))
  136.     {
  137.       /* After we have successfully collected the message we can read */
  138.       /* it, and save any important values which we maybe want to check */
  139.       /* later: */
  140.       class = my_message->Class;         /* IDCMP flag. */
  141.       code = my_message->Code;           /* Code. */
  142.  
  143.  
  144.       /* After we have read it we reply as fast as possible: */
  145.       /* REMEMBER! Do never try to read a message after you have replied! */
  146.       /* (Some other process has maybe changed it.) */
  147.       ReplyMsg( my_message );
  148.  
  149.  
  150.       /* Check which IDCMP flag was sent: */
  151.       switch( class )
  152.       {
  153.         case CLOSEWINDOW:    /* The user selected the Close window gad. */
  154.                close_me=TRUE;
  155.                break;
  156.  
  157.         case VANILLAKEY:     /* The user pressed/released a key! */
  158.                /* Print out the translated keycode (as dec. and hex.): */
  159.                printf("Translated keycode: %6d(d) %6x(h)\n\n", code, code );
  160.                
  161.                break;
  162.       }
  163.     }
  164.   }
  165.  
  166.  
  167.  
  168.   /* Close the window: */
  169.   CloseWindow( my_window );
  170.  
  171.  
  172.  
  173.   /* Close the Intuition Library: */
  174.   CloseLibrary( IntuitionBase );
  175.   
  176.   /* THE END */
  177. }
  178.